import { Injectable, EventEmitter } from '@angular/core';

import { AccountApirequest } from '../ApiRequest/Account.Apirequest';
import { accountServiceInterface } from './interface/account.service.interface';
@Injectable()
export class AccountService implements accountServiceInterface {

  constructor(
    private accountApirequest: AccountApirequest
  ) { }

  /**
   * @desc 獲取登錄用戶的信息
   * @return Promise
   */
  async getCurrentUserInfo(): Promise<User> {
    return await this.accountApirequest.currentUser();
  }

  /**
   * 
   * @param OldPassword 旧密码
   * @param NewPassword 新密码
   */
  async changePassword(OldPassword: string, NewPassword: string): Promise<void> {
    return await this.accountApirequest.changePassword(OldPassword, NewPassword);
  }

  /**
   * 
   * @param UserName 新的用户名
   */
  async update(UserName: string): Promise<void> {
    return await this.accountApirequest.update(UserName);
  }

}

export class User {
  "UserId": string;
  "UserName": string;
  "Role": {
    "RoleId": string,
    "RoleName": string
  }
}